package com.bwf.json;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;
import com.bwf.pojo.Student;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/6/13 10:40
 * @Copyright 博为峰
 */
public class FastJsonDemo {
    public static void main(String[] args) {
        Student student = new Student(1, "张三", "男", new Date(), 5000, new Date(), new Date(), 1);
        //对象->json
        String jsonString = JSONObject.toJSONString(student);
        //{"classID":1,"createTime":1655089477784,"date":1655089477784,"id":1,"name":"张三","salary":5000,"sex":"男","updateTime":1655089477784}
//        System.out.println(jsonString);

        //json->对象
        Student stu2 = JSONObject.parseObject(jsonString, Student.class);
//        System.out.println(stu2);

        ArrayList<Student> list = new ArrayList<>();
        list.add(student);

        String jsonString2 = JSONObject.toJSONString(list);
        //[{"stuId":1,"name":"张三","sex":"男","date":1655099397106,"createTime":"2022-06-13 13:49:57","updateTime":1655099397106,"classID":1}]
//        System.out.println(jsonString2);

        List<Student> list2 = JSONObject.parseArray(jsonString2, Student.class);
    }

}
